package com.ruoyi.web.controller.check;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.check.domain.Attendance;
import com.ruoyi.check.service.IAttendanceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出勤管理Controller
 *
 * @author ruoyi
 * @date 2023-03-03
 */
@RestController
@RequestMapping("/check/attendance")
public class AttendanceController extends BaseController
{
    @Autowired
    private IAttendanceService attendanceService;

    /**
     * 查询出勤管理列表
     */
    @PreAuthorize("@ss.hasPermi('check:attendance:list')")
    @GetMapping("/list")
    public TableDataInfo list(Attendance attendance)
    {
        startPage();
        List<Attendance> list = attendanceService.selectAttendanceList(attendance);
        return getDataTable(list);
    }

    /**
     * 导出出勤管理列表
     */
    @PreAuthorize("@ss.hasPermi('check:attendance:export')")
    @Log(title = "出勤管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Attendance attendance)
    {
        List<Attendance> list = attendanceService.selectAttendanceList(attendance);
        ExcelUtil<Attendance> util = new ExcelUtil<Attendance>(Attendance.class);
        util.exportExcel(response, list, "出勤管理数据");
    }

    /**
     * 获取出勤管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('check:attendance:query')")
    @GetMapping(value = "/{atId}")
    public AjaxResult getInfo(@PathVariable("atId") Integer atId)
    {
        return success(attendanceService.selectAttendanceByAtId(atId));
    }

    /**
     * 新增出勤管理
     */
    @PreAuthorize("@ss.hasPermi('check:attendance:add')")
    @Log(title = "出勤管理", businessType = BusinessType.INSERT)
    @PostMapping
    //public AjaxResult add(@RequestBody Attendance attendance)
    public boolean add(@RequestBody Attendance attendance)
    {
        return attendanceService.insertAttendance(attendance);
        //return toAjax(attendanceService.insertAttendance(attendance));
    }

    /**
     * 修改出勤管理
     */
    @PreAuthorize("@ss.hasPermi('check:attendance:edit')")
    @Log(title = "出勤管理", businessType = BusinessType.UPDATE)
    @PutMapping
    //public AjaxResult edit(@RequestBody Attendance attendance)
    public boolean edit(@RequestBody Attendance attendance)
    {
        //return toAjax(attendanceService.updateAttendance(attendance));
        return attendanceService.updateAttendance(attendance);
    }

    /**
     * 删除出勤管理
     */
    @PreAuthorize("@ss.hasPermi('check:attendance:remove')")
    @Log(title = "出勤管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{atIds}")
    public AjaxResult remove(@PathVariable Integer[] atIds)
    {
        return toAjax(attendanceService.deleteAttendanceByAtIds(atIds));
    }

    /**
     * 获取当前为星期几
     */
    @PreAuthorize("@ss.hasPermi('check:attendance:getDataCount')")
    @Log(title = "出勤管理", businessType = BusinessType.DELETE)
    @GetMapping("/getDataCount")
    public Map<String,Integer> getDataCount()
    {
        return attendanceService.getDataCount();
    }


}
